{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-26T03:56:23.462650Z",
     "start_time": "2025-09-26T03:56:20.612866Z"
    }
   },
   "source": [
    "from time import sleep\n",
    "\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "import time\n",
    "\n",
    "wd = webdriver.Chrome()\n",
    "wd.implicitly_wait(10)\n",
    "wd.get('https://www.byhy.net/cdn2/files/selenium/sample4.html')\n",
    "\n",
    "from selenium.webdriver.common.action_chains import ActionChains\n",
    "ac = ActionChains(wd)\n",
    "\n",
    "# 光标悬停到元素上\n",
    "ac.move_to_element(\n",
    "    wd.find_element(By.CSS_SELECTOR, '.navbar-nav > li.dropdown')\n",
    ")\n",
    "time.sleep(3)\n",
    "\n",
    "# 拖放元素\n",
    "for i in range(1,6):\n",
    "    ac.drag_and_drop(\n",
    "        wd.find_element(By.ID, f'course-{i}'),\n",
    "        wd.find_element(By.ID,'selected-courses')\n",
    "    ).perform()\n",
    "\n",
    "    time.sleep(0.5)\n",
    "\n",
    "wd.quit()"
   ],
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Timeout value connect was <object object at 0x00000258EB279C90>, but it must be an int, float or None.",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[3], line 7\u001B[0m\n\u001B[0;32m      4\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mselenium\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mwebdriver\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mcommon\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mby\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m By\n\u001B[0;32m      5\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtime\u001B[39;00m\n\u001B[1;32m----> 7\u001B[0m wd \u001B[38;5;241m=\u001B[39m \u001B[43mwebdriver\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mChrome\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m      8\u001B[0m wd\u001B[38;5;241m.\u001B[39mimplicitly_wait(\u001B[38;5;241m10\u001B[39m)\n\u001B[0;32m      9\u001B[0m wd\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mhttps://www.byhy.net/cdn2/files/selenium/sample4.html\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\chrome\\webdriver.py:76\u001B[0m, in \u001B[0;36mWebDriver.__init__\u001B[1;34m(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)\u001B[0m\n\u001B[0;32m     73\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mservice\u001B[38;5;241m.\u001B[39mstart()\n\u001B[0;32m     75\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m---> 76\u001B[0m     \u001B[43mRemoteWebDriver\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[38;5;21;43m__init__\u001B[39;49m\u001B[43m(\u001B[49m\n\u001B[0;32m     77\u001B[0m \u001B[43m        \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[0;32m     78\u001B[0m \u001B[43m        \u001B[49m\u001B[43mcommand_executor\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mChromeRemoteConnection\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m     79\u001B[0m \u001B[43m            \u001B[49m\u001B[43mremote_server_addr\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mservice\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mservice_url\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m     80\u001B[0m \u001B[43m            \u001B[49m\u001B[43mkeep_alive\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mkeep_alive\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m     81\u001B[0m \u001B[43m        \u001B[49m\u001B[43mdesired_capabilities\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mdesired_capabilities\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m     82\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mException\u001B[39;00m:\n\u001B[0;32m     83\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mquit()\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:157\u001B[0m, in \u001B[0;36mWebDriver.__init__\u001B[1;34m(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)\u001B[0m\n\u001B[0;32m    154\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m browser_profile \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    155\u001B[0m     warnings\u001B[38;5;241m.\u001B[39mwarn(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mPlease use FirefoxOptions to set browser profile\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[0;32m    156\u001B[0m                   \u001B[38;5;167;01mDeprecationWarning\u001B[39;00m, stacklevel\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m2\u001B[39m)\n\u001B[1;32m--> 157\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mstart_session\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcapabilities\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbrowser_profile\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    158\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_switch_to \u001B[38;5;241m=\u001B[39m SwitchTo(\u001B[38;5;28mself\u001B[39m)\n\u001B[0;32m    159\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_mobile \u001B[38;5;241m=\u001B[39m Mobile(\u001B[38;5;28mself\u001B[39m)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:252\u001B[0m, in \u001B[0;36mWebDriver.start_session\u001B[1;34m(self, capabilities, browser_profile)\u001B[0m\n\u001B[0;32m    249\u001B[0m w3c_caps \u001B[38;5;241m=\u001B[39m _make_w3c_caps(capabilities)\n\u001B[0;32m    250\u001B[0m parameters \u001B[38;5;241m=\u001B[39m {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcapabilities\u001B[39m\u001B[38;5;124m\"\u001B[39m: w3c_caps,\n\u001B[0;32m    251\u001B[0m               \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdesiredCapabilities\u001B[39m\u001B[38;5;124m\"\u001B[39m: capabilities}\n\u001B[1;32m--> 252\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mexecute\u001B[49m\u001B[43m(\u001B[49m\u001B[43mCommand\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mNEW_SESSION\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mparameters\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    253\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124msessionId\u001B[39m\u001B[38;5;124m'\u001B[39m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m response:\n\u001B[0;32m    254\u001B[0m     response \u001B[38;5;241m=\u001B[39m response[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m'\u001B[39m]\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:319\u001B[0m, in \u001B[0;36mWebDriver.execute\u001B[1;34m(self, driver_command, params)\u001B[0m\n\u001B[0;32m    316\u001B[0m         params[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124msessionId\u001B[39m\u001B[38;5;124m'\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msession_id\n\u001B[0;32m    318\u001B[0m params \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_wrap_value(params)\n\u001B[1;32m--> 319\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcommand_executor\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mexecute\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdriver_command\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mparams\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    320\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response:\n\u001B[0;32m    321\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39merror_handler\u001B[38;5;241m.\u001B[39mcheck_response(response)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py:374\u001B[0m, in \u001B[0;36mRemoteConnection.execute\u001B[1;34m(self, command, params)\u001B[0m\n\u001B[0;32m    372\u001B[0m data \u001B[38;5;241m=\u001B[39m utils\u001B[38;5;241m.\u001B[39mdump_json(params)\n\u001B[0;32m    373\u001B[0m url \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m'\u001B[39m \u001B[38;5;241m%\u001B[39m (\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_url, path)\n\u001B[1;32m--> 374\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_request\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcommand_info\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43murl\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbody\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mdata\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\selenium\\webdriver\\remote\\remote_connection.py:397\u001B[0m, in \u001B[0;36mRemoteConnection._request\u001B[1;34m(self, method, url, body)\u001B[0m\n\u001B[0;32m    394\u001B[0m     body \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[0;32m    396\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkeep_alive:\n\u001B[1;32m--> 397\u001B[0m     resp \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_conn\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrequest\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmethod\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43murl\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbody\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mbody\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mheaders\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mheaders\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    399\u001B[0m     statuscode \u001B[38;5;241m=\u001B[39m resp\u001B[38;5;241m.\u001B[39mstatus\n\u001B[0;32m    400\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\_request_methods.py:143\u001B[0m, in \u001B[0;36mRequestMethods.request\u001B[1;34m(self, method, url, body, fields, headers, json, **urlopen_kw)\u001B[0m\n\u001B[0;32m    135\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mrequest_encode_url(\n\u001B[0;32m    136\u001B[0m         method,\n\u001B[0;32m    137\u001B[0m         url,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    140\u001B[0m         \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39murlopen_kw,\n\u001B[0;32m    141\u001B[0m     )\n\u001B[0;32m    142\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 143\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mrequest_encode_body(\n\u001B[0;32m    144\u001B[0m         method, url, fields\u001B[38;5;241m=\u001B[39mfields, headers\u001B[38;5;241m=\u001B[39mheaders, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39murlopen_kw\n\u001B[0;32m    145\u001B[0m     )\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\_request_methods.py:278\u001B[0m, in \u001B[0;36mRequestMethods.request_encode_body\u001B[1;34m(self, method, url, fields, headers, encode_multipart, multipart_boundary, **urlopen_kw)\u001B[0m\n\u001B[0;32m    274\u001B[0m     extra_kw[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mheaders\u001B[39m\u001B[38;5;124m\"\u001B[39m]\u001B[38;5;241m.\u001B[39msetdefault(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mContent-Type\u001B[39m\u001B[38;5;124m\"\u001B[39m, content_type)\n\u001B[0;32m    276\u001B[0m extra_kw\u001B[38;5;241m.\u001B[39mupdate(urlopen_kw)\n\u001B[1;32m--> 278\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39murlopen(method, url, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mextra_kw)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\poolmanager.py:448\u001B[0m, in \u001B[0;36mPoolManager.urlopen\u001B[1;34m(self, method, url, redirect, **kw)\u001B[0m\n\u001B[0;32m    438\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m u\u001B[38;5;241m.\u001B[39mscheme \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    439\u001B[0m     warnings\u001B[38;5;241m.\u001B[39mwarn(\n\u001B[0;32m    440\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mURLs without a scheme (ie \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mhttps://\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m) are deprecated and will raise an error \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    441\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124min a future version of urllib3. To avoid this DeprecationWarning ensure all URLs \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    445\u001B[0m         stacklevel\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m2\u001B[39m,\n\u001B[0;32m    446\u001B[0m     )\n\u001B[1;32m--> 448\u001B[0m conn \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mconnection_from_host\u001B[49m\u001B[43m(\u001B[49m\u001B[43mu\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mhost\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mport\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mu\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mport\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mscheme\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mu\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mscheme\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    450\u001B[0m kw[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124massert_same_host\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m\n\u001B[0;32m    451\u001B[0m kw[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mredirect\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\poolmanager.py:319\u001B[0m, in \u001B[0;36mPoolManager.connection_from_host\u001B[1;34m(self, host, port, scheme, pool_kwargs)\u001B[0m\n\u001B[0;32m    316\u001B[0m request_context[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mport\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m port\n\u001B[0;32m    317\u001B[0m request_context[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mhost\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m host\n\u001B[1;32m--> 319\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mconnection_from_context\u001B[49m\u001B[43m(\u001B[49m\u001B[43mrequest_context\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\poolmanager.py:344\u001B[0m, in \u001B[0;36mPoolManager.connection_from_context\u001B[1;34m(self, request_context)\u001B[0m\n\u001B[0;32m    341\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m URLSchemeUnknown(scheme)\n\u001B[0;32m    342\u001B[0m pool_key \u001B[38;5;241m=\u001B[39m pool_key_constructor(request_context)\n\u001B[1;32m--> 344\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mconnection_from_pool_key\u001B[49m\u001B[43m(\u001B[49m\u001B[43mpool_key\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest_context\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mrequest_context\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\poolmanager.py:367\u001B[0m, in \u001B[0;36mPoolManager.connection_from_pool_key\u001B[1;34m(self, pool_key, request_context)\u001B[0m\n\u001B[0;32m    365\u001B[0m     host \u001B[38;5;241m=\u001B[39m request_context[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mhost\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[0;32m    366\u001B[0m     port \u001B[38;5;241m=\u001B[39m request_context[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mport\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[1;32m--> 367\u001B[0m     pool \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_new_pool\u001B[49m\u001B[43m(\u001B[49m\u001B[43mscheme\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mhost\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mport\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest_context\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mrequest_context\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    368\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mpools[pool_key] \u001B[38;5;241m=\u001B[39m pool\n\u001B[0;32m    370\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m pool\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\poolmanager.py:281\u001B[0m, in \u001B[0;36mPoolManager._new_pool\u001B[1;34m(self, scheme, host, port, request_context)\u001B[0m\n\u001B[0;32m    278\u001B[0m     \u001B[38;5;28;01mfor\u001B[39;00m kw \u001B[38;5;129;01min\u001B[39;00m SSL_KEYWORDS:\n\u001B[0;32m    279\u001B[0m         request_context\u001B[38;5;241m.\u001B[39mpop(kw, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[1;32m--> 281\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m pool_cls(host, port, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mrequest_context)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\connectionpool.py:193\u001B[0m, in \u001B[0;36mHTTPConnectionPool.__init__\u001B[1;34m(self, host, port, timeout, maxsize, block, headers, retries, _proxy, _proxy_headers, _proxy_config, **conn_kw)\u001B[0m\n\u001B[0;32m    190\u001B[0m RequestMethods\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__init__\u001B[39m(\u001B[38;5;28mself\u001B[39m, headers)\n\u001B[0;32m    192\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(timeout, Timeout):\n\u001B[1;32m--> 193\u001B[0m     timeout \u001B[38;5;241m=\u001B[39m \u001B[43mTimeout\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfrom_float\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    195\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m retries \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    196\u001B[0m     retries \u001B[38;5;241m=\u001B[39m Retry\u001B[38;5;241m.\u001B[39mDEFAULT\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\util\\timeout.py:186\u001B[0m, in \u001B[0;36mTimeout.from_float\u001B[1;34m(cls, timeout)\u001B[0m\n\u001B[0;32m    172\u001B[0m \u001B[38;5;129m@classmethod\u001B[39m\n\u001B[0;32m    173\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mfrom_float\u001B[39m(\u001B[38;5;28mcls\u001B[39m, timeout: _TYPE_TIMEOUT) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m Timeout:\n\u001B[0;32m    174\u001B[0m \u001B[38;5;250m    \u001B[39m\u001B[38;5;124;03m\"\"\"Create a new Timeout from a legacy timeout value.\u001B[39;00m\n\u001B[0;32m    175\u001B[0m \n\u001B[0;32m    176\u001B[0m \u001B[38;5;124;03m    The timeout value used by httplib.py sets the same timeout on the\u001B[39;00m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    184\u001B[0m \u001B[38;5;124;03m    :rtype: :class:`Timeout`\u001B[39;00m\n\u001B[0;32m    185\u001B[0m \u001B[38;5;124;03m    \"\"\"\u001B[39;00m\n\u001B[1;32m--> 186\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mTimeout\u001B[49m\u001B[43m(\u001B[49m\u001B[43mread\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mtimeout\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mconnect\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\util\\timeout.py:115\u001B[0m, in \u001B[0;36mTimeout.__init__\u001B[1;34m(self, total, connect, read)\u001B[0m\n\u001B[0;32m    109\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21m__init__\u001B[39m(\n\u001B[0;32m    110\u001B[0m     \u001B[38;5;28mself\u001B[39m,\n\u001B[0;32m    111\u001B[0m     total: _TYPE_TIMEOUT \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m,\n\u001B[0;32m    112\u001B[0m     connect: _TYPE_TIMEOUT \u001B[38;5;241m=\u001B[39m _DEFAULT_TIMEOUT,\n\u001B[0;32m    113\u001B[0m     read: _TYPE_TIMEOUT \u001B[38;5;241m=\u001B[39m _DEFAULT_TIMEOUT,\n\u001B[0;32m    114\u001B[0m ) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m--> 115\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_connect \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_validate_timeout\u001B[49m\u001B[43m(\u001B[49m\u001B[43mconnect\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mconnect\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m    116\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_read \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_validate_timeout(read, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mread\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    117\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mtotal \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_validate_timeout(total, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtotal\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "File \u001B[1;32mD:\\Tools\\conda\\envs\\learn\\lib\\site-packages\\urllib3\\util\\timeout.py:152\u001B[0m, in \u001B[0;36mTimeout._validate_timeout\u001B[1;34m(cls, value, name)\u001B[0m\n\u001B[0;32m    150\u001B[0m     \u001B[38;5;28mfloat\u001B[39m(value)\n\u001B[0;32m    151\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m (\u001B[38;5;167;01mTypeError\u001B[39;00m, \u001B[38;5;167;01mValueError\u001B[39;00m):\n\u001B[1;32m--> 152\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[0;32m    153\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mTimeout value \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m was \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m, but it must be an \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m    154\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mint, float or None.\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m%\u001B[39m (name, value)\n\u001B[0;32m    155\u001B[0m     ) \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[0;32m    157\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m    158\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m value \u001B[38;5;241m<\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;241m0\u001B[39m:\n",
      "\u001B[1;31mValueError\u001B[0m: Timeout value connect was <object object at 0x00000258EB279C90>, but it must be an int, float or None."
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 弹出对话框",
   "id": "4f050135a218826e"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-22T10:22:41.077258Z",
     "start_time": "2025-09-22T10:22:27.961116Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "import time\n",
    "\n",
    "driver = webdriver.Chrome()\n",
    "driver.implicitly_wait(5)\n",
    "driver.get('https://www.byhy.net/cdn2/files/selenium/test4.html')\n",
    "\n",
    "\n",
    "# --- alert ---\n",
    "driver.find_element(By.ID, 'b1').click()\n",
    "time.sleep(2)\n",
    "# 打印 弹出框 提示信息\n",
    "print(driver.switch_to.alert.text)\n",
    "\n",
    "# 点击 OK 按钮\n",
    "driver.switch_to.alert.accept()\n",
    "time.sleep(2)\n",
    "\n",
    "driver.quit()"
   ],
   "id": "24ce714de96aa3d4",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "现在开始和白月黑羽一起学Python!\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "2fdc6ebe407f387f"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-22T10:23:44.614814Z",
     "start_time": "2025-09-22T10:23:32.124419Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "import time\n",
    "\n",
    "driver = webdriver.Chrome()\n",
    "driver.implicitly_wait(5)\n",
    "\n",
    "driver.get('https://www.byhy.net/cdn2/files/selenium/test4.html')\n",
    "\n",
    "# --- confirm ---\n",
    "time.sleep(2)\n",
    "driver.find_element(By.ID, 'b2').click()\n",
    "\n",
    "# 打印 弹出框 提示信息\n",
    "time.sleep(2)\n",
    "print(driver.switch_to.alert.text)\n",
    "\n",
    "# 点击 OK 按钮\n",
    "driver.switch_to.alert.accept()\n",
    "\n",
    "driver.find_element(By.ID, 'b2').click()\n",
    "\n",
    "# 点击 取消 按钮\n",
    "driver.switch_to.alert.dismiss()"
   ],
   "id": "606a27d97c98fa25",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你确定要和白月黑羽一起学Python吗？\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-22T10:26:29.600625Z",
     "start_time": "2025-09-22T10:26:12.788676Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "import time\n",
    "\n",
    "driver = webdriver.Chrome()\n",
    "driver.implicitly_wait(5)\n",
    "driver.get('https://www.byhy.net/cdn2/files/selenium/test4.html')\n",
    "\n",
    "\n",
    "# --- prompt ---\n",
    "time.sleep(2)\n",
    "driver.find_element(By.ID, 'b3').click()\n",
    "\n",
    "# 获取 alert 对象\n",
    "alert = driver.switch_to.alert\n",
    "\n",
    "# 打印 弹出框 提示信息\n",
    "print(alert.text)\n",
    "\n",
    "# 输入信息，并且点击 OK 按钮 提交\n",
    "alert.send_keys('web自动化 - selenium')\n",
    "time.sleep(2)\n",
    "alert.accept()\n",
    "time.sleep(2)\n",
    "\n",
    "# 点击 Cancel 按钮 取消\n",
    "driver.find_element(By.ID, 'b3').click()\n",
    "time.sleep(2)\n",
    "alert = driver.switch_to.alert\n",
    "alert.dismiss()\n",
    "driver.quit()"
   ],
   "id": "14ebad8786d16185",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你想学习的Python课程\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "cd2e6ba92e9b1913"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
